package pikes.peak;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import pikes.html.xhtml.Block;
import pikes.html.xhtml.form.Form;
import pikes.html.xhtml.text.HorizontalRule;
import pikes.peak.BlockComponent;
import pikes.peak.FormPanel;
import pikes.peak.test.AssertHtml;
import pikes.peak.test.PikesPeakComponentTestCase;

import org.springframework.web.servlet.support.RequestContext;

public class FormPanelTestCase extends PikesPeakComponentTestCase {

	@Test
	public void simple() throws Exception {
		FormPanel formPanel = new FormPanel();

		Form expected = new Form("/countries", Form.Method.POST);

		Block actual = formPanel.createHtml(new HashMap(), pikesPeakRequest.getRequestContext());
		AssertHtml.assertEquals(expected, actual);
	}

	@Test
	public void simpleAddComponent() throws Exception {
		FormPanel formPanel = new FormPanel();
		formPanel.add(new BlockComponent() {

			public Block createHtml(Map model, RequestContext requestContext) throws Exception {
				return new HorizontalRule();
			}

		});

		Form expected = new Form("/countries", Form.Method.POST);
		expected.add(new HorizontalRule());

		Block actual = formPanel.createHtml(new HashMap(), pikesPeakRequest.getRequestContext());
		AssertHtml.assertEquals(expected, actual);
	}
}
